package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 苏西西
 * Date: 2023-08-31
 * Time: 21:38
 */
public class ThreadD17 {
    //创建两个线程来阐述wait和notify的操作
    public static void main(String[] args) throws InterruptedException {
        Object obj = new Object();
        Thread t1 = new Thread(() -> {
            System.out.println("wait之前");
            try {
                synchronized (obj) {
                    obj.wait();
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("wait之后");
        });

        Thread t2 = new Thread(() -> {
            System.out.println("notify之前");
            synchronized (obj) {
                obj.notify();
            }
            System.out.println("notify之后");
        });
        t1.start();
        Thread.sleep(1000);
        t2.start();

    }
}
